home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / Xprof / xmeasure / tstcolor.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  10KB  |  479 lines

  1. /*==================================================================
  2.  *      File :          tstcolor.c
  3.  *      Package:        Xmeasure
  4.  * 
  5.  *      Author :        Aloke Gupta.
  6.  *
  7.  *  (C) Copyright 1992, Aloke Gupta.
  8.  *  All rights granted to University of Illinois Board of Regents.
  9.  *==================================================================*/
  10.  
  11. #include "perf.h"
  12.  
  13. #define MAX_PLANES 1
  14. #define NUMCOLORS  8
  15.  
  16. /* Shared variables */
  17. static XColor        xcolors[NUMCOLORS];
  18. static unsigned int  *plane_masks;
  19. static unsigned int  pmask;
  20. static unsigned long *pixels;
  21. static char          *cname = "red";
  22.  
  23. static Colormap      *colormaps;
  24. static Colormap      **cmaplist;    /* array of pointers to Colormap */
  25. static int           i;
  26.  
  27. /* ====================================================================== */
  28.  
  29. int   CreateColormap(xd, xp) 
  30. XD *xd;
  31. XParams *xp;
  32. {
  33.     for (i = 0; i < xp->itns; i++) {
  34.       colormaps[i] = XCreateColormap(xd->display, xd->window,
  35.                       xd->visual, AllocNone);
  36.       if (!colormaps[i]) {
  37.     xp->itns = i;
  38.     fprintf(stderr,"# CreateColormap: Can only create %d colormaps out of %d\n",
  39.             i , xp->itns);
  40.     return;
  41.       }
  42.     }
  43. }
  44.  
  45. int i_CreateColormap(xd, xp) 
  46. XD *xd;
  47. XParams *xp;
  48. { colormaps = (Colormap *) calloc (xp->itns, sizeof (Colormap)); }
  49.  
  50. int c_CreateColormap(xd, xp) 
  51. XD *xd;
  52. XParams *xp;
  53. {
  54.     for (i = 0; i < xp->itns; i++)
  55.     XFreeColormap(xd->display, colormaps[i]);
  56.     free(colormaps);
  57. }
  58.  
  59. /* ====================================================================== */
  60.  
  61. int   FreeColormap(xd, xp)   
  62. XD *xd;
  63. XParams *xp;
  64. {
  65.     for (i = 0; i < xp->itns; i++)
  66.     XFreeColormap(xd->display, colormaps[i]);
  67. }
  68.  
  69. int i_FreeColormap(xd, xp)   
  70. XD *xd;
  71. XParams *xp;
  72. {
  73.     colormaps = (Colormap *)  calloc (xp->itns, sizeof (Colormap));
  74.  
  75.     for (i = 0; i < xp->itns; i++) {
  76.       colormaps[i] = XCreateColormap(xd->display, xd->window,
  77.                                       xd->visual, AllocNone);
  78.       if (!colormaps[i]) {
  79.         xp->itns = i;
  80.         fprintf(stderr,"# FreeColormap: Can only create %d colormaps out of %d\n",
  81.                         i , xp->itns);
  82.         return;
  83.       }
  84.     }
  85. }
  86.  
  87. int c_FreeColormap(xd, xp)   
  88. XD *xd;
  89. XParams *xp;
  90. { free(colormaps); }
  91.  
  92. /* ====================================================================== */
  93.  
  94. int   CopyColormapAndFree(xd, xp)
  95. XD *xd;
  96. XParams *xp;
  97. {
  98.     for (i = 0; i < xp->itns; i++) {
  99.       colormaps[i] = XCopyColormapAndFree(xd->display, xd->cmap);
  100.       if (!colormaps[i]) {
  101.         xp->itns = i;
  102.         fprintf(stderr,"# CopyColormapAndFree: Can only create %d colormaps out of %d\n",
  103.                         i , xp->itns);
  104.         return;
  105.       }
  106.     }
  107. }
  108.  
  109. int i_CopyColormapAndFree(xd, xp)
  110. XD *xd;
  111. XParams *xp;
  112. { colormaps = (Colormap *) calloc (xp->itns, sizeof (Colormap)); }
  113.  
  114. int c_CopyColormapAndFree(xd, xp)
  115. XD *xd;
  116. XParams *xp;
  117. {
  118.     for (i = 0; i < xp->itns; i++)
  119.         XFreeColormap(xd->display, colormaps[i]);
  120.     free(colormaps);
  121. }
  122.  
  123. /* ====================================================================== */
  124.  
  125. int   InstallColormap(xd, xp)
  126. XD *xd;
  127. XParams *xp;
  128. {
  129.     for (i = 0; i < xp->itns; i++) {
  130.     if (!XInstallColormap(xd->display, xd->cmap)) {
  131.         fprintf(stderr, "# InstallColormap: Cannot install %dth colormap\n",
  132.                 i);
  133.         xp->itns=i;
  134.         return ;
  135.     }
  136.     }
  137. }
  138.  
  139. int i_InstallColormap(xd, xp)
  140. XD *xd;
  141. XParams *xp;
  142. { }
  143.  
  144. int c_InstallColormap(xd, xp)
  145. XD *xd;
  146. XParams *xp;
  147. { }
  148.  
  149. /* ====================================================================== */
  150.  
  151. int   UninstallColormap(xd, xp)
  152. XD *xd;
  153. XParams *xp;
  154. {
  155.     for (i = 0; i < xp->itns; i++)
  156.     XUninstallColormap(xd->display, xd->cmap);
  157. }
  158.  
  159. int i_UninstallColormap(xd, xp)
  160. XD *xd;
  161. XParams *xp;
  162. { }
  163.  
  164. int c_UninstallColormap(xd, xp)
  165. XD *xd;
  166. XParams *xp;
  167. { }
  168.  
  169. /* ====================================================================== */
  170.  
  171. int   ListInstalledColormaps(xd, xp)
  172. XD *xd;
  173. XParams *xp;
  174. {
  175.     int num;
  176.  
  177.     for (i = 0; i < xp->itns; i++) 
  178.     cmaplist[i] = XListInstalledColormaps(xd->display, xd->window, &num);
  179. }
  180.  
  181. int i_ListInstalledColormaps(xd, xp)
  182. XD *xd;
  183. XParams *xp;
  184.     cmaplist = (Colormap **) calloc (xp->itns, sizeof (Colormap *));
  185. }
  186.  
  187. int c_ListInstalledColormaps(xd, xp)
  188. XD *xd;
  189. XParams *xp;
  190. {
  191.     for (i = 0; i < xp->itns; i++)
  192.     XFree((caddr_t) cmaplist[i]);
  193.     free(cmaplist);
  194. }
  195.  
  196. /* ====================================================================== */
  197.  
  198. int   AllocColor(xd, xp)     
  199. XD *xd;
  200. XParams *xp;
  201. {
  202.     for (i = 0; i < xp->itns; i++){
  203.     if (!XAllocColor(xd->display, xd->cmap, &xcolors[0])) {
  204.         fprintf(stderr,"# AllocColor: Cannot allocate %dth color\n", i);
  205.     }
  206.     }
  207. }
  208.  
  209. int i_AllocColor(xd, xp)     
  210. XD *xd;
  211. XParams *xp;
  212.     XParseColor(xd->display, xd->cmap, cname, &xcolors[0]);
  213. }
  214.  
  215. int c_AllocColor(xd, xp)     
  216. XD *xd;
  217. XParams *xp;
  218. { }
  219.  
  220. /* ====================================================================== */
  221.  
  222. int   AllocNamedColor(xd, xp)
  223. XD *xd;
  224. XParams *xp;
  225. {
  226.     for (i = 0; i < xp->itns; i++) {
  227.     if (!XAllocNamedColor(xd->display,xd->cmap,cname,&xcolors[0],&xcolors[1]))
  228.         fprintf(stderr,"#AllocNamedColor: Cannot allocate %dth color\n",i);
  229.     }
  230. }
  231.  
  232. int i_AllocNamedColor(xd, xp)
  233. XD *xd;
  234. XParams *xp;
  235. { }
  236.  
  237. int c_AllocNamedColor(xd, xp)
  238. XD *xd;
  239. XParams *xp;
  240. { }
  241.  
  242. /* ====================================================================== */
  243.  
  244. int   AllocColorCells(xd, xp)
  245. XD *xd;
  246. XParams *xp;
  247. {
  248.  
  249.     for (i = 0; i < xp->itns; i++) {
  250.     if (!XAllocColorCells(xd->display, xd->cmap, False,  
  251.         plane_masks + (i * MAX_PLANES), MAX_PLANES,
  252.         pixels      + (i * NUMCOLORS ), NUMCOLORS)) {
  253.     /*
  254.         fprintf(stderr,
  255.            "\n# AllocColorCells: Cannot allocate %d cells for the %d itn\n",
  256.             NUMCOLORS, i);
  257.         fflush(stderr);
  258.     */
  259.         xp->itns = i;
  260.         return;
  261.     }
  262.     }
  263. }
  264.  
  265. int i_AllocColorCells(xd, xp)
  266. XD *xd;
  267. XParams *xp;
  268.     plane_masks = (unsigned *)      calloc(MAX_PLANES * xp->itns,
  269.                         sizeof(unsigned));
  270.     pixels    = (unsigned long *) calloc(NUMCOLORS * xp->itns,
  271.                         sizeof(unsigned long));
  272. }
  273.  
  274. int c_AllocColorCells(xd, xp)
  275. XD *xd;
  276. XParams *xp;
  277.     pmask=0;
  278.     if (xp->itns > 0)
  279.       for (i=0; i <MAX_PLANES; i++)
  280.     pmask |= plane_masks[i];
  281.     for (i = 0; i < xp->itns; i++) {
  282.     XFreeColors(xd->display, xd->cmap, 
  283.         pixels      + (i * NUMCOLORS), NUMCOLORS,
  284.         pmask);
  285.     }
  286.     free(plane_masks);
  287.     free(pixels);
  288. }
  289.  
  290. /* ====================================================================== */
  291.  
  292. int   AllocColorPlanes(xd, xp)
  293. XD *xd;
  294. XParams *xp;
  295. {
  296. }
  297.  
  298. int i_AllocColorPlanes(xd, xp)
  299. XD *xd;
  300. XParams *xp;
  301. {
  302. }
  303.  
  304. int c_AllocColorPlanes(xd, xp)
  305. XD *xd;
  306. XParams *xp;
  307. {
  308. }
  309.  
  310. /* ====================================================================== */
  311.  
  312. int   FreeColors(xd, xp)     
  313. XD *xd;
  314. XParams *xp;
  315. {
  316.     for (i = 0; i < xp->itns; i++) 
  317.         XFreeColors(xd->display,xd->cmap,pixels+(i*NUMCOLORS),NUMCOLORS,pmask);
  318. }
  319.  
  320. int i_FreeColors(xd, xp)     
  321. XD *xd;
  322. XParams *xp;
  323. {
  324.     plane_masks = (unsigned *)     calloc(MAX_PLANES*xp->itns,sizeof(unsigned));
  325.     pixels    = (unsigned long *) calloc(NUMCOLORS*xp->itns,sizeof(unsigned));
  326.  
  327.     for (i = 0; i < xp->itns; i++) {
  328.         if (!XAllocColorCells(xd->display, xd->cmap, False,
  329.                 plane_masks + (i * MAX_PLANES), MAX_PLANES,
  330.                 pixels      + (i * NUMCOLORS ), NUMCOLORS)) {
  331.             xp->itns = i;
  332.             return;
  333.         }
  334.     }
  335.     pmask=0;
  336.     for (i=0; i <MAX_PLANES; i++)
  337.         pmask |= plane_masks[i];
  338. }
  339.  
  340. int c_FreeColors(xd, xp)     
  341. XD *xd;
  342. XParams *xp;
  343. {
  344.     free(plane_masks);
  345.     free(pixels);
  346. }
  347.  
  348. /* ====================================================================== */
  349.  
  350. int   StoreColors(xd, xp)    
  351. XD *xd;
  352. XParams *xp;
  353. {
  354.     for (i = 0; i < xp->itns; i++)
  355.     XStoreColors(xd->display, xd->cmap, xcolors, NUMCOLORS);
  356. }
  357.  
  358. int i_StoreColors(xd, xp)    
  359. XD *xd;
  360. XParams *xp;
  361.     plane_masks = (unsigned *)      calloc(MAX_PLANES, sizeof(unsigned));
  362.     pixels    = (unsigned long *) calloc(NUMCOLORS,  sizeof(unsigned));
  363.  
  364.     if (!XAllocColorCells(xd->display, xd->cmap, False,  plane_masks,
  365.                 MAX_PLANES, pixels, NUMCOLORS)) {
  366.     fprintf(stderr,"\n# StoreColors: Cannot allocate %d cells to test\n",
  367.                 NUMCOLORS); fflush(stderr);
  368.     xp->itns = 0;
  369.     return;
  370.     }
  371.     for (i = 0; i < NUMCOLORS; i++) {
  372.     XParseColor(xd->display, xd->cmap, cname, &xcolors[i]);
  373.     xcolors[i].pixel = pixels[i];
  374.     }
  375. }
  376.  
  377. int c_StoreColors(xd, xp)    
  378. XD *xd;
  379. XParams *xp;
  380. {
  381.     pmask=0;
  382.     for (i=0; i < MAX_PLANES; i++)
  383.     pmask |= plane_masks[i];
  384.     if (xp->itns !=0)
  385.     XFreeColors(xd->display, xd->cmap, pixels, NUMCOLORS, pmask);
  386.     free(plane_masks);
  387.     free(pixels);
  388. }
  389.  
  390. /* ====================================================================== */
  391.  
  392. int   StoreNamedColor(xd, xp)
  393. XD *xd;
  394. XParams *xp;
  395. {
  396.     for (i = 0; i < xp->itns; i++)
  397.         XStoreNamedColor(xd->display, xd->cmap, cname,
  398.                 pixels[0], DoRed | DoGreen| DoBlue);
  399. }
  400.  
  401. int i_StoreNamedColor(xd, xp)
  402. XD *xd;
  403. XParams *xp;
  404. {
  405.     plane_masks = (unsigned *)      calloc(MAX_PLANES, sizeof(unsigned));
  406.     pixels    = (unsigned long *) calloc(NUMCOLORS , sizeof(unsigned));
  407.  
  408.     if (!XAllocColorCells(xd->display, xd->cmap, False,  plane_masks,
  409.                             MAX_PLANES, pixels, 1)) {
  410.         fprintf(stderr,"\n# StoreNamedColor: Cannot allocate 1 cell to test\n");
  411.     fflush(stderr);
  412.         xp->itns = 0;
  413.         return;
  414.     }
  415. }
  416.  
  417. int c_StoreNamedColor(xd, xp)
  418. XD *xd;
  419. XParams *xp;
  420. {
  421.     pmask=0;
  422.     for (i=0; i < MAX_PLANES; i++)
  423.         pmask |= plane_masks[i];
  424.     if (xp->itns !=0)
  425.     XFreeColors(xd->display, xd->cmap, pixels, 1, pmask);
  426.     free(plane_masks);
  427.     free(pixels);
  428. }
  429.  
  430. /* ====================================================================== */
  431.  
  432. int   QueryColors(xd, xp)    
  433. XD *xd;
  434. XParams *xp;
  435. {
  436.     for (i = 0; i < xp->itns; i++)
  437.     XQueryColors(xd->display, xd->cmap, xcolors, NUMCOLORS);
  438. }
  439.  
  440. int i_QueryColors(xd, xp)    
  441. XD *xd;
  442. XParams *xp;
  443. {
  444.     for (i = 0; i < NUMCOLORS; i++)
  445.     xcolors[i].pixel = BlackPixel(xd->display, xd->screen);
  446. }
  447.  
  448. int c_QueryColors(xd, xp)    
  449. XD *xd;
  450. XParams *xp;
  451. { }
  452.  
  453. /* ====================================================================== */
  454.  
  455. int   LookupColor(xd, xp)    
  456. XD *xd;
  457. XParams *xp;
  458. {
  459.     for (i = 0; i < xp->itns; i++)
  460.     XLookupColor(xd->display, xd->cmap, cname, &xcolors[0], &xcolors[1]);
  461. }
  462.  
  463. int i_LookupColor(xd, xp)    
  464. XD *xd;
  465. XParams *xp;
  466. { }
  467.  
  468. int c_LookupColor(xd, xp)    
  469. XD *xd;
  470. XParams *xp;
  471. { }
  472.  
  473. /* ====================================================================== */
  474.